<?php

/**
 * sysUser actions.
 *
 * @package    iEasy
 * @subpackage sysUser
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sysUserActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
      $submitType = $request->getParameter("submitType");
      if($submitType != null)
      {
          if("search"!=$submitType){
          $content=$request->getParameter("content");
          if(!empty($content))
          {
              $Ids=explode(" ",$content);
              for($i=0;$i<count($Ids);$i++)
              {
                  if(!empty($Ids[$i]))
                  {
                      $duser=@Doctrine_Core::getTable('SystemUser')->find($Ids[$i]);
                      switch($submitType)
                      {
                          case "access": //
                              if($duser->getIsActivateB() == 0)
                              {
                                  $duser->setIsActivateB(1); //
                              }
                              break;
                          case "unaccess":
                              if($duser->getIsActivateB() == 1)
                              {
                                  $duser->setIsActivateB(0); //
                              }
                              break;
                      }
                      $duser->save();
                  }
              }
          }
      }
      }
     $this->recordCount=$request->getParameter('recordCount');
     $this->currentPage=$request->getParameter('currentPage');
     if(null==$this->recordCount||""==$this->recordCount)
         $this->recordCount=20;
     if(null==$this->currentPage||""==$this->currentPage)
         $this->currentPage=1;
     $query = Doctrine_Query::create()->from("SystemUser u");
     $this->searchProperty = $request->getParameter("searchProperty");
      switch($this->searchProperty)
      {
          case "access":
              $query = $query->andWhere("is_activate_b=1");
              break;
          case "unaccess":
              $query = $query->andWhere("is_activate_b=0");
              break;
      }
      $this->searchField = $request->getParameter("searchField");
      $this->searchText = trim($request->getParameter("searchText"));
      if(!empty($this->searchText)){
          switch($this->searchField)
          {
              case "uid":
                  $query = $query->andWhere("system_user_id = ?",$this->searchText);
                  break;
              case "uname":
                  $query = $query->andWhere("name like ?","%".$this->searchText."%");
                  break;
              case "unick":
                  $query = $query->andWhere("nickname like ?","%".$this->searchText."%");
                  break;
          }
      }
     $query = $query ->orderBy('u.system_user_id desc');
     $this->pages = new sfDoctrinePager('SystemUser',$this->recordCount);//$this->currentPage
     $this->pages->setQuery($query);  //$q   数据库查询语句
     $this->pages->setPage($this->currentPage);//
     $this->pages->init();
  }
    public function executeEdit(sfWebRequest $request)
    {
        $this->contEdit=$request->getParameter("contentEdit");
        $this->results=0;
        switch($this->contEdit){
            case "1":
                $this->sysUser=@Doctrine_Core::getTable('SystemUser')->find($request->getParameter("content"));
                break;
            case "2":
                $sysUser=@Doctrine_Core::getTable('SystemUser')->find($request->getParameter("content"));
                if(null!=$request->getParameter("password")&&""!=$request->getParameter("password"))
                    $sysUser->setPassword($request->getParameter("password"));
                $sysUser->setNickname($request->getParameter("nickname"));
                $sysUser->setRealName($request->getParameter("realname"));
                $sysUser->setEmail($request->getParameter("email"));
                $sysUser->setTelephone($request->getParameter("telephone"));
                $sysUser->setCellphone($request->getParameter("cellphone"));
                $sysUser->setQq($request->getParameter("qq"));
                $sysUser->setMsn($request->getParameter("msn"));
                $sysUser->save();
                $this->results=1;
                $this->sysUser=$sysUser;
                break;
        }
  }

    public function executeAdd(sfWebRequest $request)
    {
      $this->contEdit=$request->getParameter("contentEdit");
      $this->results=0;
      switch($this->contEdit){
          case "2":
              $userList = Doctrine_Core::getTable("SystemUser")->createQuery() ->where("name=?",$request->getParameter("name"))->execute();
              if(count($userList)>0)
              {
                 $this->results=2;
              }else{
              $sysUser=new SystemUser();
              $sysUser->setName($request->getParameter("name"));
              $sysUser->setNickname($request->getParameter("nickname"));
              $sysUser->setPassword($request->getParameter("password"));
              $sysUser->setRealName($request->getParameter("realname"));
              $sysUser->setEmail($request->getParameter("email"));
              $sysUser->setTelephone($request->getParameter("telephone"));
              $sysUser->setCellphone($request->getParameter("cellphone"));
              $sysUser->setQq($request->getParameter("qq"));
              $sysUser->setMsn($request->getParameter("msn"));
              $sysUser->setCatalogList("All");
              $sysUser->setIsActivateB(1);
              $sysUser->save();
              if($sysUser->getSystemUserId()>0)
                  $this->results=1;
              }
              break;
      }
  }

}
